n = input()
if n.isdigit() and len(n) == 4:
    a1 = n[0]
    a2 = n[1]
    a3 = n[2]
    a4 = n[3]
    s = []
    count1 = 0
    for i in range(1, 10000):
        if int(a1 + a2) % i == 0:
            count1 += 1
            if count1 == 2:
                s.append(int(a1 + a2))
    count2 = 0
    for i in range(1, 10000):
        if int(a2 + a3) % i == 0:
            count2 += 1
    if count2 == 2:
        s.append(int(a2 + a3))
    count3 = 0
    for i in range(1, 10000):
        if int(a3 + a4) % i == 0:
            count3 += 1
    if count3 == 2:
        s.append(int(a3 + a4))
    count4 = 0
    for i in range(1, 10000):
        if int(a1 + a3) % i == 0:
            count4 += 1
    if count4 == 2:
        s.append(int(a1 + a3))
    count5 = 0
    for i in range(1, 10000):
        if int(a1 + a4) % i == 0:
            count5 += 1
    if count5 == 2:
        s.append(int(a1 + a4))
    count6 = 0
    for i in range(1, 10000):
        if int(a2 + a4) % i == 0:
            count1 += 1
    if count6 == 2:
        s.append(int(a2 + a4))
    count7 = 0
    for i in range(1, 10000):
        if int(a1 + a2 + a3) % i == 0:
            count7 += 1
    if count7 == 2:
        s.append(int(a1 + a2 + a3))
    count8 = 0
    for i in range(1, 10000):
        if int(a2 + a3 + a4) % i == 0:
            count8 += 1
    if count8 == 2:
        s.append(int(a2 + a3 + a4))
    count9 = 0
    for i in range(1, 10000):
        if int(a1 + a2 + a3 + a4) % i == 0:
            count9 += 1
    if count9 == 2:
        s.append(int(a1 + a2 + a3 + a4))
    count10 = 0
    for i in range(1, 10000):
        if int(a1) % i == 0:
            count10 += 1
    if count10 == 2:
        s.append(int(a1))
    count11 = 0
    for i in range(1, 10000):
        if int(a2) % i == 0:
            count11 += 1
    if count11 == 2:
        s.append(int(a2))
    count12 = 0
    for i in range(1, 10000):
        if int(a3) % i == 0:
            count12 += 1
    if count12 == 2:
        s.append(int(a3))
    count13 = 0
    for i in range(1, 10000):
        if int(a4) % i == 0:
            count13 += 1
    if count13 == 2:
        s.append(int(a4))
    if len(s) <= 0:
        print(0)
    else:
        print(max(s))
else:
    print(0)